home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / ltp_drawgroup.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  10KB  |  405 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /****************************************************************************/
  15.  
  16. #include <hardware/blit.h>
  17.  
  18. /****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /****************************************************************************/
  23.  
  24. #define MINTERM_B_OR_C      (ABC | ABNC | NABC | NABNC | ANBC | NANBC)
  25. #define MINTERM_B_EQUALS_C  (ABC | ANBNC | NABC | NANBNC)
  26.  
  27. /****************************************************************************/
  28.  
  29. VOID
  30. LTP_DrawObjectLabel(LayoutHandle *Handle,ObjectNode *Node)
  31. {
  32.     if(Node->Label)
  33.     {
  34.         LONG Left,Top,GlyphHeight = Handle->GlyphHeight;
  35.  
  36.         switch(Node->LabelPlace)
  37.         {
  38.             case PLACE_LEFT:
  39.  
  40.                 Left    = Node->Left;
  41.                 Top        = Node->Top + (Node->Height - GlyphHeight) / 2;
  42.  
  43.                 break;
  44.  
  45.             case PLACE_RIGHT:
  46.  
  47.                 Left    = Node->Left + Node->Width + INTERWIDTH + INTERWIDTH + Node->LabelWidth;
  48.                 Top        = Node->Top + (Node->Height - GlyphHeight) / 2;
  49.  
  50.                 break;
  51.  
  52.             case PLACE_ABOVE:
  53.  
  54.                 Left    = Node->Left + (Node->Width - Node->LabelWidth) / 2 + INTERWIDTH + Node->LabelWidth;
  55.                 Top        = Node->Top - (GlyphHeight + INTERHEIGHT);
  56.  
  57.                 break;
  58.  
  59.             case PLACE_BELOW:
  60.  
  61.                 Left    = Node->Left + (Node->Width - Node->LabelWidth) / 2 + INTERWIDTH + Node->LabelWidth;
  62.                 Top        = Node->Top + Node->Height + INTERHEIGHT;
  63.  
  64.                 break;
  65.  
  66.             default:
  67.  
  68.                 return;    /* Only if none of the placement types match; should never happen! */
  69.         }
  70.  
  71.         LTP_PrintLabel(Handle,Node,Left,Top);
  72.     }
  73. }
  74.  
  75. VOID
  76. LTP_DrawGroup(LayoutHandle *Handle,ObjectNode *Group)
  77. {
  78.     ObjectNode *Node;
  79.     ULONG page;
  80.     LONG i;
  81.  
  82.     if(Group->Label || Group->Special.Group.Frame || Group->Special.Group.FrameType == FRAMETYPE_Label)
  83.         LTP_DrawGroupLabel(Handle,Group);
  84.     else
  85.     {
  86.         if(Group->Special.Group.FrameType == FRAMETYPE_Tab)
  87.             LTP_DrawGroupFrame(Handle,Group);
  88.     }
  89.  
  90.     SCANPAGE(Group,Node,page)
  91.     {
  92.         switch(Node->Type)
  93.         {
  94.             case BLANK_KIND:
  95.  
  96.                 break;
  97.  
  98.             #ifdef OLD_STYLE_DEFAULT_KEY
  99.             {
  100.                 case BUTTON_KIND:
  101.  
  102.                     if(Handle->ReturnKey == Node)
  103.                         LTP_DrawBevelBox(Handle,Node);
  104.  
  105.                     break;
  106.             }
  107.             #endif
  108.  
  109.             #ifdef DO_GAUGE_KIND
  110.             {
  111.                 case GAUGE_KIND:
  112.                 {
  113.                     LONG Percent = Node->Current;
  114.  
  115.                     Node->Current = 0;
  116.  
  117.                     LTP_DrawGauge(Handle,Node,Percent,TRUE);
  118.  
  119.                     break;
  120.                 }
  121.             }
  122.             #endif
  123.  
  124.             case PALETTE_KIND:
  125.  
  126.                 if(Node->Special.Palette.UsePicker)
  127.                     LTP_DrawPalette(Handle,Node);
  128.  
  129.                 break;
  130.  
  131.             case GROUP_KIND:
  132.  
  133.                 if(Node->Label)
  134.                     LTP_DrawGroupLabel(Handle,Node);
  135.  
  136.                 LTP_DrawGroup(Handle,Node);
  137.  
  138.                 break;
  139.  
  140.             case XBAR_KIND:
  141.             {
  142.                 LONG Top = Node->Top + ((Node->Height + 1) / 2) - 1;
  143.                 struct RastPort *RPort = &Handle->RPort;
  144.  
  145.                 if(Node->Special.Bar.FullSize)
  146.                 {
  147.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  148.                     LTP_DrawLine(RPort,Handle->Window->BorderLeft,Top,Handle->Window->Width - (Handle->Window->BorderRight + 1),Top);
  149.  
  150.                     LTP_SetAPen(RPort,Handle->ShinePen);
  151.                     LTP_DrawLine(RPort,Handle->Window->BorderLeft,Top + 1,Handle->Window->Width - (Handle->Window->BorderRight + 1),Top + 1);
  152.                 }
  153.                 else
  154.                 {
  155.                     LONG Room,Left;
  156.  
  157.                     Left = Node->Special.Bar.Parent->Left;
  158.  
  159.                     if(Node->Special.Bar.Parent->Label)
  160.                         Room = 2 * Handle->GlyphWidth;
  161.                     else
  162.                         Room = 0;
  163.  
  164.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  165.                     LTP_PolyDraw(RPort,3,
  166.                         Left + Room,Top + 1,
  167.                         Left + Room,Top,
  168.                         Left + Node->Special.Bar.Parent->Width - 1 - 1 - Room,Top);
  169.  
  170.                     LTP_SetAPen(RPort,Handle->ShinePen);
  171.                     LTP_PolyDraw(RPort,3,
  172.                         Left + Room + 1,Top + 1,
  173.                         Left + Node->Special.Bar.Parent->Width - 1 - Room,Top + 1,
  174.                         Left + Node->Special.Bar.Parent->Width - 1 - Room,Top);
  175.                 }
  176.  
  177.                 break;
  178.             }
  179.  
  180.             case YBAR_KIND:
  181.             {
  182.                 LONG Left = Node->Left + ((Node->Width + 1) / 2) - 1,Room;
  183.                 struct RastPort *RPort = &Handle->RPort;
  184.  
  185.                 if(Node->Special.Bar.Parent->Label)
  186.                     Room = Handle->GlyphHeight + Handle->InterHeight;
  187.                 else
  188.                     Room = 0;
  189.  
  190.                 LTP_SetAPen(RPort,Handle->ShadowPen);
  191.                 LTP_PolyDraw(RPort,3,
  192.                     Left + 1,    Node->Special.Bar.Parent->Top + Room,
  193.                     Left,        Node->Special.Bar.Parent->Top + Room,
  194.                     Left,        Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - 1 - Room);
  195.  
  196.                 LTP_SetAPen(RPort,Handle->ShinePen);
  197.                 LTP_PolyDraw(RPort,3,
  198.                     Left + 1,    Node->Special.Bar.Parent->Top + Room + 1,
  199.                     Left + 1,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room,
  200.                     Left,        Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  201.  
  202.                 if((Handle->AspectY + Handle->AspectX - 1) / Handle->AspectX >= 2)
  203.                 {
  204.                     LTP_SetAPen(RPort,Handle->ShadowPen);
  205.                     LTP_DrawLine(RPort,    Left - 1,    Node->Special.Bar.Parent->Top + Room,
  206.                                 Left - 1,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  207.  
  208.                     LTP_SetAPen(RPort,Handle->ShinePen);
  209.                     LTP_DrawLine(RPort,    Left + 2,    Node->Special.Bar.Parent->Top + Room,
  210.                                 Left + 2,    Node->Special.Bar.Parent->Top + Node->Special.Bar.Parent->Height - 1 - Room);
  211.                 }
  212.  
  213.                 break;
  214.             }
  215.  
  216.             case IMAGE_KIND:
  217.  
  218.                 if(Node->Special.Image.Image != NULL)
  219.                     DrawImage(&Handle->RPort,Node->Special.Image.Image,Node->Left,Node->Top);
  220.                 else
  221.                 {
  222.                     UWORD    left    = Node->Special.Image.BitMapLeft,
  223.                             top        = Node->Special.Image.BitMapTop,
  224.                             width    = Node->Special.Image.BitMapWidth,
  225.                             height    = Node->Special.Image.BitMapHeight;
  226.  
  227.                     if(Node->Special.Image.BitMapMask == NULL)
  228.                     {
  229.                         BltBitMapRastPort(Node->Special.Image.BitMap,left,top,
  230.                                           &Handle->RPort,Node->Left,Node->Top,
  231.                                           width,height,0xC0);
  232.                     }
  233.                     else
  234.                     {
  235.                         struct BitMap *source = Node->Special.Image.BitMap;
  236.                         struct RastPort *destination = &Handle->RPort;
  237.                         BOOL isInterleaved = FALSE;
  238.  
  239.                         if(V39)
  240.                         {
  241.                             if(GetBitMapAttr(Node->Special.Image.BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  242.                                 isInterleaved = TRUE;
  243.                         }
  244.  
  245.                         if(isInterleaved)
  246.                         {
  247.                             struct BitMap mask;
  248.                             LONG i;
  249.  
  250.                             InitBitMap(&mask,8,GetBitMapAttr(Node->Special.Image.BitMap,BMA_WIDTH),GetBitMapAttr(Node->Special.Image.BitMap,BMA_HEIGHT));
  251.                             for(i = 0 ; i < 8 ; i++)
  252.                                 mask.Planes[i] = Node->Special.Image.BitMapMask;
  253.  
  254.                             BltBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_EQUALS_C);
  255.                             BltBitMapRastPort(&mask,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_OR_C);
  256.                             BltBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,MINTERM_B_EQUALS_C);
  257.                         }
  258.                         else
  259.                         {
  260.                             BltMaskBitMapRastPort(source,left,top,destination,Node->Left,Node->Top,width,height,(ABC | ABNC | ANBC),Node->Special.Image.BitMapMask);
  261.                         }
  262.                     }
  263.                 }
  264.  
  265.                 LTP_DrawObjectLabel(Handle,Node);
  266.                 break;
  267.  
  268.             case FRAME_KIND:
  269.  
  270.                 if(Node->Special.Frame.DrawBox)
  271.                     LTP_DrawBevelBox(Handle,Node);
  272.  
  273.                 if(Node->Special.Frame.RefreshHook)
  274.                 {
  275.                     RefreshMsg Message;
  276.  
  277.                     Message.ID        = Node->ID;
  278.                     Message.Left    = Node->Left;
  279.                     Message.Top        = Node->Top;
  280.                     Message.Width    = Node->Width;
  281.                     Message.Height    = Node->Height;
  282.  
  283.                     if(Node->Special.Frame.DrawBox)
  284.                     {
  285.                         Message.Left    += 4;
  286.                         Message.Top        += 2;
  287.                         Message.Width    -= 8;
  288.                         Message.Height    -= 4;
  289.                     }
  290.  
  291.                     CallHookPkt(Node->Special.Frame.RefreshHook,Handle,&Message);
  292.                 }
  293.  
  294.                 // FALL THROUGH TO...
  295.  
  296.             case BOOPSI_KIND:
  297.  
  298.                 // FALL THROUGH TO...
  299.  
  300.             case POPUP_KIND:
  301.  
  302.                 // FALL THROUGH TO...
  303.  
  304.             case TAPEDECK_KIND:
  305.  
  306.                 LTP_DrawObjectLabel(Handle,Node);
  307.                 break;
  308.  
  309.             case MX_KIND:
  310.  
  311.                 if(Node->Label && !V39)
  312.                     LTP_PrintLabel(Handle,Node,Node->Left,Node->Top + (Node->Height - Handle->GlyphHeight) / 2 + 1);
  313.  
  314.                 break;
  315.  
  316.             #ifdef DO_LEVEL_KIND
  317.             {
  318.                 case LEVEL_KIND:
  319.  
  320.                     LTP_LevelGadgetDrawLabel(Handle,Node,TRUE);
  321.                     break;
  322.             }
  323.             #endif    /* DO_LEVEL_KIND */
  324.  
  325.             case LISTVIEW_KIND:
  326.             {
  327.                 struct RastPort *RPort = &Handle->RPort;
  328.  
  329.                 if(Node->Special.List.ExtraLabels)
  330.                 {
  331.                     LTP_SetPens(RPort,Handle->TextPen,0,JAM1);
  332.  
  333.                     for(i = 0 ; Node->Special.List.ExtraLabels[i] ; i++)
  334.                     {
  335.                         LONG Len = strlen(Node->Special.List.ExtraLabels[i]);
  336.  
  337.                         LTP_PrintText(RPort,Node->Special.List.ExtraLabels[i],Len,Node->Left - (TextLength(RPort,Node->Special.List.ExtraLabels[i],Len) + INTERWIDTH),Node->Top + 2 + i * Handle->GlyphHeight);
  338.                     }
  339.                 }
  340.  
  341.                 if(Node->Label)
  342.                 {
  343.                     if(Node->LabelPlace == PLACE_ABOVE && Node->Special.List.FlushLabelLeft)
  344.                     {
  345.                         struct TextFont *Font = NULL,*OldFont = NULL;
  346.  
  347.                         if(Node->Special.List.TextAttr)
  348.                         {
  349.                             if(Font = LTP_OpenFont(Node->Special.List.TextAttr))
  350.                             {
  351.                                 OldFont = RPort->Font;
  352.  
  353.                                 SetFont(RPort,Font);
  354.                             }
  355.                             else
  356.                                 break;
  357.                         }
  358.  
  359.                         LTP_PrintLabel(Handle,Node,Node->Left + 2 + INTERWIDTH + Node->LabelWidth,Node->Top - (Handle->GlyphHeight + INTERHEIGHT));
  360.  
  361.                         if(Font)
  362.                         {
  363.                             SetFont(RPort,OldFont);
  364.  
  365.                             CloseFont(Font);
  366.                         }
  367.                     }
  368.                     else
  369.                     {
  370.                         if(Node->Special.List.TextAttr)
  371.                             LTP_DrawObjectLabel(Handle,Node);
  372.                     }
  373.                 }
  374.  
  375.                 break;
  376.             }
  377.  
  378.             case BOX_KIND:
  379.             {
  380.                 struct RastPort *RPort = &Handle->RPort;
  381.  
  382.                 Node->Special.Box.Parent = Group;
  383.  
  384.                 if(Node->Special.Box.DrawBox)
  385.                     LTP_DrawBevelBox(Handle,Node);
  386.  
  387.                 for(i = 0 ; i < Node->Lines ; i++)
  388.                 {
  389.                     if(Node->Special.Box.Labels && Node->Special.Box.Labels[i])
  390.                     {
  391.                         LONG Len = strlen(Node->Special.Box.Labels[i]);
  392.  
  393.                         LTP_SetPens(RPort,Handle->TextPen,0,JAM1);
  394.                         LTP_PrintText(RPort,Node->Special.Box.Labels[i],Len,Node->Left - (TextLength(RPort,Node->Special.Box.Labels[i],Len) + INTERWIDTH),Node->Top + 2 + i * (Handle->GlyphHeight + Node->Special.Box.Spacing));
  395.                     }
  396.  
  397.                     LTP_PrintBoxLine(Handle,Node,i);
  398.                 }
  399.  
  400.                 break;
  401.             }
  402.         }
  403.     }
  404. }
  405.